package dieLock;

public class DeadLock {
    private static String t1 = new String();
    private static String t2 = new String();

    public static void main(String[] args) {

        new Thread( () -> {
            synchronized (t1){
                sleep(100);
                System.out.println("线程1，等待t2");
                synchronized (t2){
                    System.out.println("获取到t2,线程1完成");
                }
            }
        } ).start();

        new Thread( () -> {
            synchronized (t2){
                sleep(100);
                System.out.println("线程2，等待t1");
                synchronized (t1){
                    System.out.println("获取到t1，线程2完成");
                }
            }
        } ).start();
    }

    private static void sleep(int ms){
        try {
            Thread.sleep(ms);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}
